/**
    * Created by haolw on 5/10/17.
    */
bookApp.controller('BorrowRecordsController', function($scope, $rootScope, $http, $filter,ngTableParams,$resource, $modal) {

    $scope.paginationConf={
        currentPage:1,
        totalItems:0,
        itemsPerPage: 30
    };

    $scope.borrowRecordsTableParams = new ngTableParams({
        page: 1,
        count: 100
    },{
        total: 0,
        counts:[],
        getData: function ($defer, params) {
            var queryParams = {pageNo:$scope.paginationConf.currentPage,pageSize:$scope.paginationConf.itemsPerPage};
            $http.get("/api/book/borrowed-record",{params:queryParams}).success(function(data){
                if(data.code == 200){
                    $scope.records = data.data.result;
                    $scope.paginationConf.totalItems = data.data.totalCount;
                    $defer.resolve($scope.records);
                }
            });
        }
    });

    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', function () {
        $scope.borrowRecordsTableParams.reload();
    });

});